#include "Acceptor.hpp"
#include "EventLoop.hpp"
#include "TcpConnection.hpp"

#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
using std::cout;
using std::endl;


void onConnection(wd::TcpConnectionPtr conn)
{
    //获取连接的信息
    cout << conn->toString() << " has connected.\n";
}

void onMessage(wd::TcpConnectionPtr conn)
{
    //消息到达时的处理方式
    cout << "recv msg: " << conn->receive() << endl;
    conn->send("welecome to server.");
}

void onClose(wd::TcpConnectionPtr conn)
{
    //连接断开时的处理
    cout << conn->toString() << " has closed.\n";
}



 
int main(void)
{
	wd::Acceptor acceptor(8000);
	acceptor.ready();

    wd::EventLoop loop(acceptor);
    loop.setAllCallbacks(onConnection,
                         onMessage,
                         onClose);
    loop.loop();//开始事件循环
	return 0;
}
